<template>
  <div class="flowpath-container">
    <div>
      <div class="mb20">
        <span class="color_494949 ft12 pr5 w70">{{ translate('单号') }}：</span>
        <el-input
          v-model="searchInfo1"
          class="w192 mr10"
          :placeholder="translate('请输入单号')"
        />
        <span class="color_494949 ft12 pr5 w70">{{ translate('品类名称') }}：</span>
        <el-input
          v-model="searchInfo2"
          class="w192 mr10"
          :placeholder="translate('请输入品类名称')"
        />
        <span class="color_494949 ft12 pr5 w70">{{ translate('品类编码') }}：</span>
        <el-input
          v-model="searchInfo3"
          class="w192 mr10"
          :placeholder="translate('请输入品类编码')"
        />
        <span class="color_494949 ft12 pr5 w70">{{ translate('审核状态') }}：</span>
        <el-select
          v-model="Remark"
          class="w192"
          :placeholder="translate('请选择')"
         >
          <el-option
            v-for="item in RemarkArry"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
          </el-select>
        <el-button class="settingBtn ml10" type="primary" @click="getList">
          {{ translate('查询') }}
        </el-button>
        <!-- <el-button class="settingBtn mr10" type="primary" @click="resetFn">
          {{ translate('重置') }}
        </el-button> -->
      </div>
      <div class="add">
        <el-button
          v-if="MenuAuths('add')"
          class="settingBtn"
          type="primary"
          @click="addFn"
          plain
        >
          {{ translate('新增') }}
        </el-button>
        <el-button
          v-if="MenuAuths('add')"
          class="settingBtn"
          type="primary"
          @click="exportFn"
          plain
        >
          {{ translate('导出') }}
        </el-button>
        <el-upload
          accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel"
          :action="action"
          :before-upload="beforeUpload"
          class="ml-upload"
          :headers="headers"
          name="fileInput"
          :on-error="handleError"
          :on-success="handleSuccess"
          :show-file-list="false"
        >
          <ElButton type="primary" @click="uploadFn()" plain>
            {{ translate('导入') }}
          </ElButton>
        </el-upload>
        <el-button
          v-if="MenuAuths('add')"
          class="settingBtn"
          type="primary"
          @click="withdrawFn"
          plain
        >
          {{ translate('撤回') }}
        </el-button>
      </div>
      <el-table
          :data="tableData"
          v-loading="loading"
          :row-class-name="tableRowClassName"
          :row-key="getRowKey"
          @selection-change="handleSelectionChange"
          >
        <el-table-column prop="value" type="selection" width="55" />
        <el-table-column :label="translate('单号')">
          <template #default="{ row }">
            <div>
              <span class="iconcolor">{{ row.ICANo }}</span>
              <vab-icon icon="file-copy-line" @click="copyToClipboard(row.ICANo)" />
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column :label="translate('品类编码')">
          <template #default="{ row }">
            <div>
              <span class="iconcolor">{{ row.CategoryCode }}</span>
              <vab-icon icon="file-copy-line" @click="copyToClipboard(row.CategoryCode)" />
            </div>
          </template>
        </el-table-column>
        <el-table-column :label="translate('品类名称')" prop="CategoryName" /> -->
        <el-table-column :label="translate('3.0物料码')" prop="SysItemCode30" />
        <el-table-column :label="translate('3.0品类编码')" prop="CategoryCode" />
        <el-table-column :label="translate('3.0物料描述')" prop="SysItemRemark30" />
        <el-table-column :label="translate('2.0物料码')" prop="SysItemCode20" />
        <el-table-column :label="translate('2.0品名')" prop="SysItemName20" />
        <!-- <el-table-column :label="translate('2.0物料描述')" prop="SysItemRemark" /> -->
        <el-table-column :label="translate('审核状态')">
          <template #default="{ row }">
            <div>
              <el-tag type="success" v-if="row.AuditStatus.includes('已审核')">{{ row.AuditStatus }}</el-tag>
              <el-tag type="danger" v-if="row.AuditStatus.includes('已结束')">{{ row.AuditStatus }}</el-tag>
              <el-tag v-if="row.AuditStatus.includes('流转中')">{{ row.AuditStatus }}</el-tag>
              <el-tag type="info" v-if="row.AuditStatus && row.AuditStatus !== '已审核' && row.AuditStatus !== '已结束' && !row.AuditStatus.includes('流转中')">{{ row.AuditStatus }}</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          :label="translate('创建时间')"
          prop="CreateDate"
          show-overflow-tooltip
          min-width="170"
        />
        <el-table-column
          :label="translate('创建人')"
          prop="CreateUserName"
          show-overflow-tooltip
        />
        <el-table-column :label="translate('备注')" prop="Remark" />
        <el-table-column :label="translate('操作')" width="300">
          <template #default="{ row }">
            <el-button plain size="small" type="primary" @click="examineFn(row)">
              {{ translate('审核') }}
            </el-button>
            <!-- <el-button plain size="small" type="primary" @click="FexamineFn(row)">
              {{ translate('反审核') }}
            </el-button> -->
            <el-button
              v-if="MenuAuths('edit')"
              plain
              size="small"
              type="primary"
              @click="detailFn(row)"
            >
              {{ translate('编辑') }}
            </el-button>
            <el-button
              v-if="MenuAuths('delete')"
              plain
              size="small"
              type="danger"
              @click="deletedFn(row)"
            >
              {{ translate('删除') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination
          background
          :current-page="pageNo"
          :layout="layout"
          :page-size="pageSize"
          :total="total"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>
    <el-dialog
      v-model="dialogVisible"
      :title="translate(title)"
      width="1340px"
      @close="closeFn"
      :close-on-click-modal="false"
    >
      <detail
        :chileddetail="chileddetail"
        :extralist="Extralist"
        :form="form"
        fromtype="goodslist"
        :purchaselist="PurchaseList"
        :supplierdata="SupplierData"
        :whdata="WHdata"
        @changelist="changeList"
        @deletedchild="deletedchild"
        @changeextralist="changeExtralist"
      />
      <template #footer>
        <el-button @click="dialogVisible = false">
          {{ translate('取消') }}
        </el-button>
        <el-button :disabled="isclick" type="primary" @click="submit">
          {{ translate('确定') }}
        </el-button>
      </template>
    </el-dialog>
    <!-- 打印页面 -->
    <el-dialog v-model="isPrint" center width="1450px" @close="isPrint = false" :close-on-click-modal="false" >
      <print
        ref="tableRef"
        :chileddetail="chiledPrintdetail"
        :form="form"
        fromprint="goodsList"
        :supplierdata="SupplierData"
      />
      <template #footer>
        <el-button @click="isPrint = false">{{ translate('取消') }}</el-button>
        <el-button type="primary" @click="submitPrint">
          {{ translate('打印') }}
        </el-button>
      </template>
    </el-dialog>
    <wordflow
      :drawershow="isdrawershow"
      :formid="formId"
      :nodelist="nodeList"
      @handclose="handleClose"
    />
  </div>
</template>

<script>
  import {
    ItemCodeApplyMasterData,
    ItemCodeApplyMasterDelData,
    ItemCodeApplyMasterUpdateData,
    ItemCodeApplyMasterAdd,
    ItemCodeApplyMasterDetail,
    Wms_PurchaseList,
    startflow,
    ItemCodeApplyExport,
    Cancel_AuditItemCodeApply,
    withdraw,
  } from '@/api/form'
  import detail from './components/detail'
  import wordflow from '@/views/components/wordflow/index'
  import print from './components/print'
  import { MenuAuth } from '~/src/utils/permission'
  import VabPrint from '@/plugins/VabPrint'
  import { translate } from '@/i18n'
  import { parseTime } from '@/utils'
  import { baseURL } from '@/config'
  import { useUserStore } from '@/store/modules/user'
  const { token } = useUserStore()
  const userStore = useUserStore()
  const { realname } = storeToRefs(userStore)
  export default defineComponent({
    name: 'Flowpath',
    components: { detail, wordflow, print },
    data() {
      return {
        tableData: [],
        searchInfo1: '',
        searchInfo2: '',
        searchInfo3: '',
        wheres: '',
        total: 0,
        pageNo: 1,
        pageSize: 20,
        title: '',
        dialogVisible: false,
        enabled: 0,
        DetailPageData: {},
        chileddetail: [],
        updataData: [],
        chiledPrintdetail: [],
        Extralist: [],
        isclick: false,
        submitType: 'add',
        action: '',
        headers: '',
        layout: 'total, sizes, prev, pager, next, jumper',
        deleList: [],
        MenuAuths: '',
        tableRef: null,
        isPrint: false,
        loading: false,
        PurchaseList: [],
        isdrawershow: false,
        nodeList: {},
        formId: '',
        status: -1,
        WHdata: [],
        PBMID: '',
        selectArr: [],
        Remark: '',
        form: {
          CategoryCode: '',
          CategoryName: '',
          SysItemCode20: '',
          SysItemCode30: '',
          SysItemName20: '',
          SysItemRemark: '',
          Remark: '',
        },
        RemarkArry: [
          {
            label: '全部',
            value: '全部',
          },
          {
            label: '草稿',
            value: '0',
          },
          {
            label: '流转中',
            value: '1',
          },
          {
            label: '已结束',
            value: '2',
          },
          {
            label: '被返回',
            value: '-1',
          },
          {
            label: '被拒绝',
            value: '-2',
          },
          {
            label: '其它',
            value: '其它',
          }
        ],
        rules: {
          code: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入工号'),
            },
          ],
          Account: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入登录账号'),
            },
          ],
          workFlowName: [
            {
              required: true,
              trigger: 'blur',
              message: translate('请输入账号名称'),
            },
          ],
        },
      }
    },
    created() {
      this.MenuAuths = MenuAuth
      this.getList()
    },
    methods: {
      tableRowClassName({ row, rowIndex }) {
        row.row_index = rowIndex
      },
      handleSelectionChange(e) {
        this.selectArr = e
      },
      getRowKey(row) {
        return row.PBMID
      },
      async uploadFn() {
        this.loading = true
        this.headers = this.headers = {
          Authorization: `Bearer ${token}`,
        }
        this.action = `${baseURL}/Wms_ItemCodeApplyMaster/ImportItemCodeApply`
      },
      handleError(data) {
        console.log(data)
        this.loading = false
      },
      handleSuccess(data) {
        this.loading = false
        if (data.code === '200') {
          this.$message({
            type: 'success',
            message: data.message,
          })
          this.getList()
        } else {
          this.$message({
            message: data.message,
            type: 'error',
          })
        }
      },
      withdrawFn() {
        if(this.selectArr.length<=0){
          this.$message({
            message: translate('请选择要撤回的单据'),
            type: 'warning',
          })
          return
        }else {
          this.$confirm(translate('确认撤回流转中订单吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            console.log(this.selectArr)
            this.withdraws()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
        }
      },
      async withdraws() {
        const formIdArr = []
        this.selectArr.map((item,index) =>{
             formIdArr.push(
              {
                keyValue: item.ICAMId,
                workFlowCode: 'Wms_ItemCodeApplyMaster'
              }
             )
        })
        const params = formIdArr
        const data = await withdraw(params)
        if(data.Code === '200'){
          this.$message({
            message: translate('已撤回流转中订单'),
            type: 'success',
          })
          this.getList()
        }else {
          this.$message({
            message: data.Message,
            type: 'error',
          })
        }
        console.log(data)
      },
      resetFn() {
        this.searchInfo1 = ''
        this.searchInfo2 = ''
        this.searchInfo3 = ''
        this.pageNo = 1
        this.pageSize = 20
        this.getList()
      },
      async ZFFn(row) {
        this.formId = row.PBMID
          this.$router.push({
            path: '/table/detail',
            query: {
              formId: this.formId,
              formcode: 'Wms_PickingBillMaster',
              type: 'zf',
              statusSH: row.BillStatus
            },
        })
      },
      //复制标识
      async copyToClipboard(val) {
        if (navigator.clipboard && window.isSecureContext) {
          try {
          console.log(navigator.clipboard)
          console.log(window.isSecureContext)
          await navigator.clipboard.writeText(val)
          this.$message({
            message:'复制成功',
            type:'success',
          })
          } catch (err) {
            this.$message({
            message:'复制失败',
            type:'error',
          })
          }

        }else {
          // 创建text area
        const textArea = document.createElement("textarea")
        textArea.value = val
        // 使text area不在viewport，同时设置不可见
        textArea.style.position = "absolute"
        textArea.style.opacity = 0
        textArea.style.left = "-999999px"
        textArea.style.top = "-999999px"
        document.body.appendChild(textArea)
        textArea.focus()
        textArea.select()

        return new Promise((res, rej) => {
          // 执行复制命令并移除文本框
          document.execCommand("copy") ? res() : rej()
          textArea.remove()
        }).then(() => {
          this.$message({
              message: "复制成功",
              type: "success",
            })
          }).catch((err) => {
            this.$message({
              message: "复制失败",
              type: "error",
            })
          })
        }

      },
      exportFn() {
        if(this.selectArr.length<=0){
          this.$message({
            message: translate('请选择要导出的单据'),
            type: 'warning',
          })
          return
        }else {
          this.$confirm(translate('确认导出选中的单据吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            console.log(this.selectArr)
            this.loading = true
            this.download()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消导出'),
            })
          })
        }
      },
       // 下载物资表
       async download() {
        const formIdArr = []
        this.selectArr.map((item,index) =>{
             formIdArr.push(
              {
                keyValue: item.ICAMId,
              }
             )
        })
        const params = formIdArr
        const data = await ItemCodeApplyExport(params)
        const time = parseTime(new Date().getTime(), '{y}{m}{d}{h}{i}{s}')
        const blob = new Blob([data])
        const url = URL.createObjectURL(blob)
        const link = document.createElement('a')
        this.loading = false
        link.download = `物码申请单${time}.xlsx`
        link.href = url
        link.click()
      },
      // 下载物资表
      // async download() {
      //   this.wheres = ''
      //   this.loading = true
      //   if (this.searchInfo3 || this.searchInfo1 || this.searchInfo2) {
      //     const arr = []
      //     this.searchInfo1.trim() !== '' &&
      //       arr.push({
      //         name: 'ICANo',
      //         value: this.searchInfo1,
      //         displayType: 'like',
      //       })
      //     this.searchInfo3.trim() !== '' &&
      //       arr.push({
      //         name: 'CategoryCode',
      //         value: this.searchInfo3,
      //         displayType: 'like',
      //       })
      //     this.searchInfo2.trim() !== '' &&
      //       arr.push({
      //         name: 'CategoryName',
      //         value: this.searchInfo2,
      //         displayType: 'like',
      //       })
      //     this.wheres = JSON.stringify(arr)
      //   }
      //   const params = {
      //     pageNo: this.pageNo,
      //     pageSize: this.pageSize,
      //     tableName: '',
      //     sort: '',
      //     order: '',
      //     wheres: this.wheres,
      //     export: false,
      //     value: '',
      //     openid: this.Remark === '全部' ? '' : this.Remark === '其它' ? '其它' : this.Remark
      //   }
      //   const data = await ItemCodeApplyExport(params)
      //   const time = parseTime(new Date().getTime(), '{y}{m}{d}{h}{i}{s}')
      //   const blob = new Blob([data])
      //   const url = URL.createObjectURL(blob)
      //   const link = document.createElement('a')
      //   link.download = `物码申请单${time}.xlsx`
      //   link.href = url
      //   link.click()
      //   this.loading = false
      // },
      translate(row) {
        return translate(row)
      },
      handleClose() {
        this.isdrawershow = false
      },
      async submitPrint() {
        document.title = '领料单'
        await VabPrint(this.$refs.tableRef)
        this.isPrint = false
      },
      changeExtralist(val) {
        this.Extralist = val
      },
      changeList(val) {
        console.log(val)
        this.chileddetail = val?.PurchaseOrderDetail
        this.form = {
          IBType: val.IBType,
          InComeNo: val.InComeNo,
          AcceptanceNo: val.AcceptanceNo,
          SourceBillNo: val.SourceBillNo,
          Supplier: val.Supplier,
          CCode: val.CCode,
          EntrustNo: val.EntrustNo,
          CustomizeNo: val.CustomizeNo,
          ProjectName: val.ProjectName,
          WorkBillNo: val.WorkBillNo,
          AcceptanceConclusion: val.AcceptanceConclusion,
          CategoryNumber: val.CategoryNumber,
          InComeDate: val.InComeDate,
          PurchaseNo: val.PurchaseNo,
          Description: val.Description,
          Documenter: val.Documenter,
          MaterialReceiver: val.MaterialReceiver,
          FinancialReviewer: val.FinancialReviewer,
        }
      },
      async Wms_PurchaseList() {
        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: '',
        }
        const data = await Wms_PurchaseList(params)
        if (data.code === '200') {
          this.PurchaseList = data.data.rows
        }
      },
      async FexamineFn(row) {
        this.$confirm(translate('确认反审核该笔订单吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            this.CancelAuditItemCodeApply(row)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
      },
      async CancelAuditItemCodeApply(row) {
            const params = {
              formId: row.ICAMId
            }
            const data = await Cancel_AuditItemCodeApply(params)
            if(data.result.code === '200') {
              this.$message({
                message: translate('操作成功'),
                type: 'success',
              })
              await this.getList()
            }else {
              this.$message({
                message: translate(data.result.message),
                type: 'error',
              })
            }
      },
      async examineFn(row) {
        this.loading = true
        const params = {
          keyValue: row.ICAMId,
          code: 'Wms_ItemCodeApplyMaster',
          formUrl: 'Wms_ItemCodeApplyMaster',
          flowData: null,
        }
        const data = await startflow(params)
        if (data.code === '200') {
          this.auditwms('Wms_ItemCodeApplyMaster', row.ICAMId)
          this.formId = row.ICAMId
          this.$router.push({
            path: '/table/detail',
            query: {
              formId: this.formId,
              formcode: 'Wms_ItemCodeApplyMaster',
            },
          })
        }
        this.loading = false
      },
      async auditwms(Code, id) {
        const params = {
          code: Code,
          keyValue: id,
        }
        const data = await auditwms(params)
        if (data.code === '200') {
          this.nodeList = data.data
          this.isdrawershow = true
        } else {
          this.$message({
            message: data.message,
            type: 'error',
          })
        }
      },
      async getList() {
        this.wheres = ''
        this.loading = true
        if (this.searchInfo3 || this.searchInfo1 || this.searchInfo2 ) {
          const arr = []
          this.searchInfo1.trim() !== '' &&
            arr.push({
              name: 'ICANo',
              value: this.searchInfo1,
              displayType: 'like',
            })
          this.searchInfo3.trim() !== '' &&
            arr.push({
              name: 'CategoryCode',
              value: this.searchInfo3,
              displayType: 'like',
            })
          this.searchInfo2.trim() !== '' &&
            arr.push({
              name: 'CategoryName',
              value: this.searchInfo2,
              displayType: 'like',
            })
          this.wheres = JSON.stringify(arr)
        }

        const params = {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
          tableName: '',
          sort: '',
          order: '',
          wheres: this.wheres,
          export: false,
          value: '',
          openid: this.Remark === '全部' ? '' : this.Remark === '其它' ? '其它' : this.Remark
        }
        const data = await ItemCodeApplyMasterData(params)
        this.tableData = data.data.rows
        this.total = data.data.total
        console.log(this.tableData)
        this.loading = false
      },
      deletedchild(e) {
        this.deleList = e
        console.log(e)
      },
      async deletedFn(row) {
        this.$confirm(translate('确认删除吗?'), translate('提示'), {
          confirmButtonText: translate('确定'),
          cancelButtonText: translate('取消'),
          type: 'warning',
        })
          .then(() => {
            this.deleted(row)
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: translate('已取消删除'),
            })
          })
      },
      async deleted(row) {
        const IbmID = []
        IbmID.push(row.ICAMId)
        const params = IbmID
        const data = await ItemCodeApplyMasterDelData(params)
        if (data.code == '200') {
          this.$message({
            message: translate('删除成功'),
            type: 'success',
          })
          await this.getList()
        }
      },
      //分页条数切换
      handleSizeChange(val) {
        this.pageSize = val
        this.getList()
      },
      //分页切换
      handleCurrentChange(val) {
        this.pageNo = val
        this.getList()
      },
      async addFn() {
        this.submitType = 'add'
        this.status = -1
        this.chileddetail = []
        this.title = '物码申请详情'
        this.form = {
          CategoryCode: '',
          CategoryName: '',
          SysItemCode20: '',
          SysItemCode30: '',
          SysItemName20: '',
          SysItemRemark: '',
          Remark: '',
        }
        this.dialogVisible = true
        this.deleList = []
      },
      submit() {
        console.log(this.chileddetail)
        if(!this.chileddetail) {
            this.$message({
                message: '请选择物料明细',
                type: 'warning',
              })
              return
        }
        if(this.chileddetail&&this.chileddetail.length>0) {
          let isreturn = false
          let txz = ''
          for (let index = 0; index < this.chileddetail.length; index++) {
            if((this.chileddetail[index].AttributeName1 && !this.chileddetail[index].AttributeValue1) || (this.chileddetail[index].AttributeName1 && this.chileddetail[index].AttributeValue1.trim()==='') || (this.chileddetail[index].AttributeName1 && this.chileddetail[index].AttributeValue1 === null)) {
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称1有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName2 && !this.chileddetail[index].AttributeValue2) || (this.chileddetail[index].AttributeName2 && this.chileddetail[index].AttributeValue2.trim()==='') || (this.chileddetail[index].AttributeName2 && this.chileddetail[index].AttributeValue2 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称2有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName3 && !this.chileddetail[index].AttributeValue3) || (this.chileddetail[index].AttributeName3 && this.chileddetail[index].AttributeValue3.trim()==='') || (this.chileddetail[index].AttributeName3 && this.chileddetail[index].AttributeValue3 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称3有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName4 && !this.chileddetail[index].AttributeValue4) || (this.chileddetail[index].AttributeName4 && this.chileddetail[index].AttributeValue4.trim()==='') || (this.chileddetail[index].AttributeName4 && this.chileddetail[index].AttributeValue4 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称4有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName5 && !this.chileddetail[index].AttributeValue5) || (this.chileddetail[index].AttributeName5 && this.chileddetail[index].AttributeValue5.trim()==='') || (this.chileddetail[index].AttributeName5 && this.chileddetail[index].AttributeValue5 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称5有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName6 && !this.chileddetail[index].AttributeValue6) || (this.chileddetail[index].AttributeName6 && this.chileddetail[index].AttributeValue6.trim()==='') || (this.chileddetail[index].AttributeName6 && this.chileddetail[index].AttributeValue6 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称6有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName7 && !this.chileddetail[index].AttributeValue7) || (this.chileddetail[index].AttributeName7 && this.chileddetail[index].AttributeValue7.trim()==='') || (this.chileddetail[index].AttributeName7 && this.chileddetail[index].AttributeValue7 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称7有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName8 && !this.chileddetail[index].AttributeValue8) || (this.chileddetail[index].AttributeName8 && this.chileddetail[index].AttributeValue8.trim()==='') || (this.chileddetail[index].AttributeName8 && this.chileddetail[index].AttributeValue8 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称8有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName9 && !this.chileddetail[index].AttributeValue9) || (this.chileddetail[index].AttributeName9 && this.chileddetail[index].AttributeValue9.trim()==='') || (this.chileddetail[index].AttributeName9 && this.chileddetail[index].AttributeValue9 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称9有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName10 && !this.chileddetail[index].AttributeValue10) || (this.chileddetail[index].AttributeName10 && this.chileddetail[index].AttributeValue10.trim()==='') || (this.chileddetail[index].AttributeName10 && this.chileddetail[index].AttributeValue10 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称10有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName11 && !this.chileddetail[index].AttributeValue11) || (this.chileddetail[index].AttributeName11 && this.chileddetail[index].AttributeValue11.trim()==='') || (this.chileddetail[index].AttributeName11 && this.chileddetail[index].AttributeValue11 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称11有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName12 && !this.chileddetail[index].AttributeValue12) || (this.chileddetail[index].AttributeName12 && this.chileddetail[index].AttributeValue12.trim()==='') || (this.chileddetail[index].AttributeName12 && this.chileddetail[index].AttributeValue12 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称12有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName13 && !this.chileddetail[index].AttributeValue13) || (this.chileddetail[index].AttributeName13 && this.chileddetail[index].AttributeValue13.trim()==='') || (this.chileddetail[index].AttributeName13 && this.chileddetail[index].AttributeValue13 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称13有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName14 && !this.chileddetail[index].AttributeValue14) || (this.chileddetail[index].AttributeName14 && this.chileddetail[index].AttributeValue14.trim()==='') || (this.chileddetail[index].AttributeName14 && this.chileddetail[index].AttributeValue14 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称14有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }else if((this.chileddetail[index].AttributeName15 && !this.chileddetail[index].AttributeValue15) || (this.chileddetail[index].AttributeName15 && this.chileddetail[index].AttributeValue15.trim()==='') || (this.chileddetail[index].AttributeName15 && this.chileddetail[index].AttributeValue15 === null)){
              txz = index+1
              isreturn = true
              this.$message({
                message: '第'+txz+'行特性名称15有值的特性值必填，请检查填写后在保存',
                type: 'warning',
              })
              break;
            }
            if(this.deleList.length<=0){
              const arr = this.updataData
              for (let i = 0; i < this.chileddetail.length; i++) {
              for (let j = 0; j < arr.length; j++) {
                if (this.chileddetail[i].ICADId !== arr[j].ICADId) {
                  this.deleList.push(arr[j].ICADId)
                }
              }
            }
            }

            console.log(this.updataData)
            console.log(this.chileddetail)


        }
        if(isreturn) {
             return
         }
        if (this.submitType === 'add') {
          this.AddData()
        } else {
          this.updataSaveList()
        }
      }
      },
      closeFn() {
        this.enabled = 0
        this.form.WorkFlowID = ''
      },
      async detailFn(row) {
        this.deleList = []
        this.form = row
        this.PBMID = row.ICAMId
        this.submitType = 'edit'
        this.title = '物码申请详情'+'('+row.ICANo+')'
        await this.ItemCodeApplyMasterDetail(row)
        this.dialogVisible = true
      },
      async ItemCodeApplyMasterDetail() {
        const params = {
          pageNo: 1,
          pageSize: 100,
          total: 0,
          tableName: '',
          sort: '',
          order: '',
          wheres: '',
          export: true,
          value: this.PBMID,
        }
        const data = await ItemCodeApplyMasterDetail(params)
        if (data.master) {
          this.$nextTick(() => {
            this.chileddetail = data.rows
            this.updataData = JSON.parse(JSON.stringify(data.rows))
            this.Extralist = data.extra || []
          })
        }

      },
      async AddData() {
        this.isclick = true
        const params = {
          mainData: this.form,
          detailData: this.chileddetail,
          delKeys: [],
          Extra: this.Extralist
        }
        const data = await ItemCodeApplyMasterAdd(params)
        if (data.code == '200') {
          this.getList()
          this.$message({
            message: translate('保存成功'),
            type: 'success',
          })
          this.dialogVisible = false
        }
        setTimeout(() => {
          this.isclick = false
        }, 5000)
      },
      async updataSaveList() {
        const params = {
          mainData: this.form,
          detailData: this.chileddetail,
          delKeys: this.deleList,
          Extra: this.Extralist
        }
        const data = await ItemCodeApplyMasterUpdateData(params)
        if (data.code == '200') {
          this.getList()
          this.$message({
            message: translate('保存成功'),
            type: 'success',
          })
          this.dialogVisible = false
        }
      },
    },
  })
</script>
<style lang="scss" scoped>
  .flowpath-container {
    .color_494949 {
      color: #494949;
    }
    .w192 {
      width: 192px;
    }
    .mb20 {
      margin-bottom: 20px;
    }
    .mr10 {
      margin-right: 10px;
    }
    .ml10 {
      margin-left: 10px;
    }
    .add {
      margin-bottom: 10px;
      text-align: left;
    }
    .ml-upload {
      display: inline-block;
      margin-left: 10px;
      vertical-align: bottom;
      margin-right: 10px;
    }

    .iconcommon {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: blue;
    }
    .iconcommon2 {
      position: absolute;
      top: 80px;
      right: 70px;
      font-size: 60px;
      color: red;
    }
    .w70 {
      display: inline-block;
      width: 70px;
      text-align: right;
    }
    .condition-container {
      display: inline-block;
      margin-top: 10px;
    }
    .iconcolor {
      color: #409eff;
    }
    .color_l {
      color: #67c23a;
    }
    .color_red {
      color: #f56c6c;
    }
  }
</style>
